var mapIds = [329020000, 329021000, 329022000, 329023000, 329024000];
var 准备地图 = 329000000;
var exp = 2263000;
var boss = 2600910;
var quest = 41834;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("镜世界_克里蒂亚斯_简单");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(5);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(15 * 60 * 1000);
    em.setProperty("buff", p.getAPI().rand(0, 1))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    if (em.getNumberProperty("clear" + mapIds[0]) == 1) {
        b.getAPI().updateMirrorDungeonMap(0, 1, [0])
    }
    em.setProperty("kill", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, c) {
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a);
    b.getPlayers().forEach(function (f) {
        var e = f.getMapId();
        if (c == boss) {
            f.getMap().killAllMonsters(true);
            f.getAPI().playerMessage(-1, "已经完成了所有副本。点击下方的[离开副本]按钮，可以返回村庄。");
            f.getAPI().addNumberForQuestInfo(quest, "count", 1);
            var h = f.getAPI().getNumberFromQuestInfo(quest, "count");
            var d = f.getAPI().getNumberFromQuestInfo(quest, "min");
            var g = f.getAPI().getNumberFromQuestInfo(quest, "sec");
            var i = parseInt((15 * 60 * 1000 - b.getTimeLeft()) / 1000);
            if (d == 0 && g == 0 || i < d * 60 + g) {
                f.getAPI().setNumberForQuestInfo(quest, "min", parseInt(i / 60));
                f.getAPI().setNumberForQuestInfo(quest, "sec", i % 60);
                f.getAPI().showMirrorDungeonReward(i, i, h, exp, 50, 0, 181)
            } else {
                f.getAPI().showMirrorDungeonReward(i, d * 60 + g, h, exp, 50, 0, 181)
            }
            f.getAPI().gainExp(exp);
            b.startEventTimer(15 * 1000);
            em.setProperty("clear" + e, 1)
        } else {
            if (f.getMap().getNumMonsters() == 0) {
                f.getAPI().fieldEffect_ScreenMsg("mirrorDungeon/clear");
                f.getAPI().playerMessage(-1, "已经消灭了全部敌人。请移动到下一个地图。");
                em.setProperty("clear" + e, 1);
                f.getAPI().updateMirrorDungeonMap(0, 1, [0])
            }
        }
    });
    return 1
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}

function onMonsterDamaged() {}

function onItemPickedUp() {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
};